package com.example.webcrawler.controller;

import com.example.webcrawler.dto.CrawlRequest;
import com.example.webcrawler.dto.CrawlResponse;
import com.example.webcrawler.service.WebCrawlerService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/api/crawler")
public class CrawlerController {

    private final WebCrawlerService webCrawlerService;

    @Autowired
    public CrawlerController(WebCrawlerService webCrawlerService) {
        this.webCrawlerService = webCrawlerService;
    }

    @PostMapping("/crawl")
    public CrawlResponse crawlWebsite(@RequestBody CrawlRequest request) {
        return webCrawlerService.crawlAndClassify(
                request.getUrl(),
                request.getCssSelector()
        );
    }
}
